package com.itheima.config;

import org.springframework.context.annotation.*;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@Import({MyBatisConfig.class, JdbcConfig.class})
	/*
	等同于<context:component-scan base-package="com.itheima.service">
	 */
@ComponentScan(value = "com.itheima.service")
	/*
	将MyBatisConfig类和JdbcConfig类交给Spring管理
	 */
	@EnableTransactionManagement
	public class SpringConfig {
	    //事务管理器的配置
    @Bean
    public DataSourceTransactionManager transactionManager(DataSource dataSource){
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        //配置数据源
        transactionManager.setDataSource(dataSource);
        return transactionManager;
    }
}

